
<template>
  <h1>猜猜我是谁</h1>
<input type="text" placeholder="填写你猜的数字" v-model="n1" @keydown.enter="check(n1)">
    <button @click="check(n1)"></button>
  <br>
  <p>hint:{{hint}}</p>
</template>

<script setup>
import {ref} from "vue";
const n1 =ref('');
const hint =ref('');
let rNumber = parseInt(Math.random()*100+1);

const check =(n)=> {
  console.log(typeof n);
  let n2= parseInt(n);
  if (isNaN(n2)){
    alert('输入数字');
    return;
  }
  if (n2===rNumber){
    hint.value='对了';
    return;
  }
  if (n2<rNumber){
    hint.value='小了';
    return;
  }
  else {
    hint.value='大了';
    return;
  }
}

</script>


<style scoped>

</style>